<template>
		<u-tabbar class="qyTabbar" @change="jump" :inactiveColor="'#8D8D8D'" :activeColor="'#3291F8'" v-model="current" :list="list" :mid-button="true"></u-tabbar>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
						iconPath: "/static/image/tabbar/home.png",
						selectedIconPath: "/static/image/tabbar/homeSel.png",
						text: '首页',
						customIcon: true,
						pagePath:"/pages/companyPage/home/index"
					},
					{
						iconPath: "/static/image/tabbar/work.png",
						selectedIconPath: "/static/image/tabbar/workSel.png",
						text: '灵工大厅',
						customIcon: true,
						pagePath:"/pages/companyPage/job/index"
					},
					{
						iconPath: "/static/image/tabbar/publish.png",
						selectedIconPath: "/static/image/tabbar/publish.png",
						text: '发布职位',
						midButtonSize:36,
						midButton: true,
						customIcon: true,
						// pagePath:"/pages/common/publishPage/index"
					},
					{
						iconPath: "/static/image/tabbar/chat.png",
						selectedIconPath: "/static/image/tabbar/chatSel.png",
						text: '消息',
						customIcon: true,
						// isDot:true,
						count:'',
						pagePath:"/pages/chat/index"
					},
					{
						iconPath: "/static/image/tabbar/user.png",
						selectedIconPath: "/static/image/tabbar/userSel.png",
						text: '我的',
						customIcon: true,
						pagePath:"/pages/companyPage/my/index"
					},
				],
				current: 0
			}
		},
		computed: {
			unreadCount() {
				let count = 0;
				this.chatStore.chats.forEach(chat => {
					if (!chat.delete) {
						count += chat.unreadCount;
					}
				})
				return count;
			},
			readSum(){
				return this.chatStore.readSum
			},
		},
		watch: {
			unreadCount(newCount, oldCount) {
				this.refreshUnreadBadge();
			},
			readSum(newCount, oldCount){
				this.refreshUnreadBadge()
			}
		},
		mounted() {
			this.refreshUnreadBadge()
		},
		methods:{
			async refreshUnreadBadge() {
				let data=await this.chatStore.sysNoRead()
				if (this.unreadCount > 0) {
					this.list[3].count=this.unreadCount+data.num;
				} else {
					let count=data.num>0?data.num:''
					this.list[3].count=''+count
				}
			},
			jump(e){
				if(e==2){
					uni.navigateTo({
						url:"/pages/common/publishPage/index"
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>